package com.yyplatform.admin.platform.file.service.impl;

import java.util.List;

import org.modelmapper.ModelMapper;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.stereotype.Service;

import com.yyplatform.admin.infra.utils.DateUtils;
import com.yyplatform.admin.platform.file.model.dto.SysFileDTO;
import com.yyplatform.admin.platform.file.model.dto.SysFileQueryDTO;
import com.yyplatform.admin.platform.file.model.entity.SysFileEntity;
import com.yyplatform.admin.platform.file.repository.SysFileRepository;
import com.yyplatform.admin.platform.file.service.SysFileService;
import com.yyplatform.admin.platform.file.service.SysFileUploadService;

import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
 * @author sleepforests@163.com
 * <p>
 * Created on 2024/9/21 21:28
 */
@Service
@Slf4j
@AllArgsConstructor
public class SysFileServiceImpl implements SysFileService {

    private SysFileRepository sysFileRepository;
    private ModelMapper modelMapper;

    private SysFileUploadService sysFileUploadService;

    @Override
    public Page<SysFileDTO> query(SysFileQueryDTO queryDTO) {
        Page<SysFileEntity> entityPage =
                sysFileRepository.findPage(
                        DateUtils.getBeginDate(queryDTO.getCreateTimeArr()),
                        DateUtils.getEndDate(queryDTO.getCreateTimeArr()),
                        queryDTO.getPageRequestOrderByIdDesc());

        List<SysFileDTO> list = entityPage.stream()
                .map(e -> modelMapper.map(e, SysFileDTO.class))
                .toList();

        return new PageImpl<>(list, entityPage.getPageable(), entityPage.getTotalElements());
    }

    @Override
    public void delete(Long id) {
        sysFileRepository.deleteById(id);
    }


}
